home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 15 / BBS in a box XV-1.iso / Files / Internet / Misc / Uupc 3.1 sources.sit / uupc 3.1 sources Folder / Mac specific / Unix lib / chdir.c next >
Encoding:
C/C++ Source or Header  |  1993-02-08  |  1.9 KB  |  92 lines  |  [TEXT/KAHL]

  1. #include "host.h"
  2.  
  3. #ifdef THINK_C
  4. # include "unixlibproto.h"
  5. #endif THINK_C
  6.  
  7. #include <string.h>
  8. #ifdef    TEST
  9. #    include    <stdio.h>
  10. #endif    TEST
  11. #ifndef NULL
  12. #define NULL 0L
  13. #endif
  14.  
  15. #include "chdir.proto.h"
  16. #include "pcmail.h"
  17. #include "uupcproto.h"
  18.  
  19. #define USEWD
  20.  
  21. chdir(char *path)
  22. {
  23.  
  24.     char         npath[255];
  25.     CInfoPBRec    cpb;
  26.     HParamBlockRec hpbr;
  27.     WDPBRec        wdpb;
  28.     int            vRef;
  29.     OSErr        err;
  30.  
  31.     printmsg(1, "chdir(%s)", path );
  32.     /* get default WD id */
  33.     (void)GetVol((StringPtr)npath, &vRef);
  34.     
  35.     /* convert to Mac-style pathname */
  36.     cnvMac( path, npath );
  37.  
  38.     cpb.dirInfo.ioVRefNum = 0;
  39.     cpb.dirInfo.ioNamePtr = (StringPtr)CtoPstr(npath);
  40.     cpb.dirInfo.ioFDirIndex = 0;
  41.     cpb.dirInfo.ioDrDirID = 0L;
  42.  
  43.     if ((err = PBGetCatInfo( &cpb, 0 )) != noErr ) {
  44.         printmsg(0, "chdir: PBGetCatInfo error %d on %s", err, path );
  45.         return((int)NULL);
  46.     }
  47.  
  48. #ifdef THINK_C
  49.     memset((char *)(&wdpb), (int)NULL, (size_t)sizeof(wdpb));
  50.     memset((char *)(&hpbr), (int)NULL, (size_t)sizeof(hpbr));
  51. #else THINK_C
  52.     repmem((char *)&wdpb, "", 1, sizeof(wdpb));
  53. #endif THINK_C
  54.     hpbr.volumeParam.ioVolIndex = -1;
  55.     hpbr.volumeParam.ioNamePtr = (StringPtr) npath;
  56.     if ((err = PBHGetVInfo(&hpbr, FALSE)) != noErr) {
  57.         printmsg(0, "chdir: PBHGetVInfo error %d on %s", err, path );
  58.         return((int)NULL);
  59.     }    
  60.     wdpb.ioVRefNum = hpbr.volumeParam.ioVRefNum;
  61.     wdpb.ioWDProcID = APPSIGNATURE;
  62.     wdpb.ioWDDirID = cpb.dirInfo.ioDrDirID;
  63.     if ((err = PBOpenWD(&wdpb, FALSE)) != noErr) {
  64.         printmsg(0, "chdir: PBOpenWD error %d on %s", err, path );
  65.         return((int)NULL);
  66.     }
  67.     if ((err = SetVol((int)NULL, wdpb.ioVRefNum)) != noErr) {
  68.         printmsg(0, "chdir: SetVol error %d on %s", err, path );
  69.         return((int)NULL);
  70.     }
  71.  
  72. #ifdef TEST
  73.     fprintf( stderr, "chdir: %s\n", npath );
  74. #endif
  75. #if DEBUG
  76.     printf("wd.ioVRefNum = %x, wd.ioWDDirID = %lx\n", wd.ioVRefNum, wd.ioWDDirID);
  77. #endif
  78.     return(noErr);    
  79. }
  80.  
  81. #ifdef TEST
  82. main(void)
  83. {
  84.     char command[100];
  85.  
  86.     gets( command );
  87.     fprintf( stderr, "%d\n", chdir( command ));
  88. }
  89.  
  90. #endif
  91.  
  92.